home *** CD-ROM | disk | FTP | other *** search
- ;unsigned short seek_string(strg,sub_strg,start_pt);
- ; char *strg,*sub_str;
- ; unsigned short start_pt;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _seek_string
- _seek_string proc near
- push bp ;
- mov bp,sp ;set up stack frame
- push di ;
- push si ;
- push ds ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: cmp _memory_model,2 ;data near or far?
- jb A1 ;jump if near
- lds si,dword ptr[bp+4] ;DS:SI pts to Strg
- les di,dword ptr[bp+8] ;DS:DI pts to SubStrg
- mov cx,[bp+12] ;get start_pt
- jmp short B1 ;
- A1: mov si,[bp+4] ;NEAR case
- mov di,[bp+6] ;
- mov cx,[bp+8] ;
- mov ax,ds ;ES = DS
- mov es,ax ;
- B1: push di ;figure substring length
- sub dl,dl ;count in dl
- C1: cmp byte ptr es:[di],0 ;null yet?
- je D1 ;jump if so
- inc di ;forward ptr
- inc dl ;inc counter
- jmp short C1 ;loop
- D1: pop di ;
- mov bp,3 ;error_code 3 = sub_strg is null
- or dl,dl ;sub_strg length non-zero?
- jnz F1 ;continue if so
- E1: jmp R1 ;error: quit routine
- F1: push si ;figure Strg length
- sub dh,dh ;count in dh
- G1: cmp byte ptr[si],0 ;null yet?
- je H1 ;quit if so
- inc si ;forward ptr
- inc dh ;inc counter
- jmp short G1 ;loop
- H1: pop si ;
- dec bp ;2 = Strg is null
- or dh,dh ;test for null
- jz E1 ;quit if null
- mov bl,cl ;start_pt
- add bl,dl ;sub_strg length
- cmp bl,dh ;compare to strg length
- ja E1 ;quit if out of range
- mov bp,1 ;error_code 1 = not found
- mov bl,cl ;start_pt to pos counter
- dec bl ;adjust
- sub dh,cl ;sub from search len
- inc dh ;adjust
- add si,cx ;begin search at start_pt
- I1: mov al,es:[di] ;get char from sub_strg
- mov ah,al ;copy in AH
- cmp al,97 ;low end of lower case
- jb J1 ;jump if below
- cmp al,122 ;upper end of lower case
- ja K1 ;neither upper nor lower
- sub ah,32 ;make AH upper case
- jmp short K1 ;go test both
- J1: cmp al,65 ;low end of upper case
- jb K1 ;neither upper nor lower
- cmp al,90 ;high end of upper case
- ja K1 ;neither upper nor lower
- add ah,32 ;make AH lower case
- K1: inc bl ;inc Strg pos counter
- or dh,dh ;counter = zero?
- jz R1 ;quit if so
- dec dh ;dec length counter
- mov bh,[si] ;get char from Strg
- cmp bh,al ;test for match
- je L1 ;jump if found
- cmp bh,ah ;2nd test for match
- je L1 ;jump if found
- inc si ;forward Strg ptr
- jmp short K1 ;go check next char
- L1: cmp dl,1 ;single char substring?
- jne M1 ;jump if not
- mov bp,0 ;set error_code
- jmp short S1 ;go quit
- M1: sub cx,cx ;clear CX
- mov cl,dl ;CX = Substr length
- dec cl ;1st char already matched
- push si ;save Strg position
- push di ;save Substr position
- N1: inc si ;pt to nxt char of Strg
- inc di ;pt to nxt char of Substr
- mov al,es:[di] ;get char from of Substr
- mov ah,al ;copy in AH
- cmp al,97 ;low end of lower case
- jb O1 ;jump if below
- cmp al,122 ;upper end of lower case
- ja P1 ;neither upper nor lower
- sub ah,32 ;make AH upper case
- jmp short P1 ;go test both
- O1: cmp al,65 ;low end of upper case
- jb P1 ;neither upper nor lower
- cmp al,90 ;high end of upper case
- ja P1 ;neither upper nor lower
- add ah,32 ;make AH lower case
- P1: mov bh,[si] ;get char from Strg
- cmp bh,al ;test for match
- je Q1 ;jump if found
- cmp bh,ah ;2nd test for match
- je Q1 ;jump if found
- pop di ;match not made
- pop si ;restore prior ptrs
- inc si ;forward Strg ptr
- jmp short I1 ;resume search for 1st ch
- Q1: loop N1 ;go compare next char
- pop di ;substring found!
- pop si ;balance stack
- dec bp ;error_code 0 = no error
- jmp short S1 ;go set return value
- R1: mov bl,0 ;return 0
- S1: sub bh,bh ;return value in BL, Clear BH
- mov ax,bx ;set return value
- pop ds ;restore DS
- mov bx,bp ;get return value
- mov _error_code,bl ;set _error_code
- pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _seek_string ENDP
- _TEXT ENDS
- END